#include "event.h"
event::event()
{
	FD_ZERO(&m_fdset);
	m_fd = 0;
}

event::~event()
{
}

bool  event::Initevent( uint32 a_fd)
{
	m_fd = a_fd;
	FD_SET(m_fd, &m_fdset);
	return true;
}

bool  event::Removeevent()
{
	FD_CLR(m_fd, &m_fdset);
	return true;
}

bool  event::Resetevent()
{
	FD_ZERO(&m_fdset);
}

bool  event::WaitSocketevent()
{
	struct timeval tv;
	int result;

	tv.tv_sec = 0;
	tv.tv_usec = 1000;

	result = select(m_fd + 1, &m_fdset, NULL, NULL, &tv);
	
	SetupSocketevent();
    
	//error
	if (result == -1) 
		return false;

	//	Success 
    if (result) 
		return true;

	// time out
	return false;
}

bool  event::SetupSocketevent()
{
	FD_SET(m_fd, &m_fdset);
	return true;
}
